﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Southridge.Data;
using System.Data.Objects;

namespace Southridge.Business
{
    public class ListGenerator  
    {
               
        public static List<int> GetIntList(int min, int increment, int max)
        {
            List<int> ret = new List<int>();
            for (; min < max; min += increment)
            {
                ret.Add(min); 
            }
            return ret; 
        }

        public static List<double> GetDoubleList(double min, double increment, double max)
        {
            List<double> ret = new List<double>();
            for (; min < max; min += increment)
            {
                ret.Add(min);
            }
            return ret;
        }
    }

    

    public class FilterMetadata : DataEntity 
    {
        internal FilterMetadata()
        {

        }

        private static FilterMetadata _instance; 

        public static FilterMetadata Current
        {
            get 
            {
                if (_instance == null)
                {
                    _instance = new FilterMetadata();
                }
                return _instance; 
            }     
        }

        public static List<double> Prices
        {
            get
            {
                return ListGenerator.GetDoubleList(150000, 50000, 1000000); 
            } 
        }
        public static List<int> Rooms 
        {
            
            get
            {
                return ListGenerator.GetIntList(0, 1, 8); 
            }
        }

        public static List<double> BathRooms
        {

            get
            {
                return ListGenerator.GetDoubleList(0, .5, 6 );
            }
        }


        public static List<int> Garage
        {
            get
            {
                return ListGenerator.GetIntList(0, 1, 6);
            }
        }

        public static System.Collections.IList PropertyTypes
        {
            get
            {
                return Enum.GetValues ( typeof(Southridge.Data.PropertyType)) ; 
            } 
        }

        public static List<double> SquareFootage
        {
            get
            {
                return ListGenerator.GetDoubleList( 800, 400, 8000);
            }
        }

        public static List<double> Acreage
        {
            get
            {
                return ListGenerator.GetDoubleList(1000, 500, 10000);
            }
        }

        public static List<int> PropertyAge
        {
            get
            {
                return ListGenerator.GetIntList( 1900, 10, 2010);
            }
        }

        public static List<string> YearBuilt
        {
            get
            {
                List<string> list = new List<string>(); 
                list.Add ( "<1900"); 
                list.Add ( "1900-1950") ;
                list.Add ( "1950-1970"); 
                list.Add ( "1970s"); 
                list.Add ( "1980s"); 
                list.Add ( "1990s"); 
                list.Add ( ">2000") ;
                list.Add("New");

                return list; 
             } 
        }

        public static List<State> States
        {
            get
            {
                try
                {
#if SQLCE 
                    SouthridgeDB db = DBContext.SouthridgeDB; 
                    ObjectQuery<State> states = db.State.Include("County") ;
                    System.Diagnostics.Debug.WriteLine(states.ToTraceString()); 
                    List<State> ret = states.ToList<State>();

                    foreach ( State state in ret ) 
                    { 
                        foreach ( County county in state.County ) 
                        {
                            if (!county.Neighborhood.IsLoaded)
                                county.Neighborhood.Load(); 
                        } 
                    } 
                    return ret;
#else 

                    return Database.States; 
#endif 

                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine (ex.Message); 
                }
                return null; 
            } 
        } 
    }
}
